class_name PlayerStatePreppingShot
extends PlayerState

const DURACTION_MAX_BONUS := 1000.0
const EASE_REWARD_FACTION := 2.0

var shot_direction := Vector2.ZERO
var time_start_shot := Time.get_ticks_msec()

func _enter_tree() -> void:
	animation_player.play("prep_kick")
	player.velocity = Vector2.ZERO
	time_start_shot = Time.get_ticks_msec()
	shot_direction = player.heading
	
func _process(delta: float) -> void:
	shot_direction += KeyUtil._get_input_vector(player.control_scheme) * delta
	
	if KeyUtil.is_action_just_released(player.control_scheme,KeyUtil.Action.SHOOT):
		var duraction_press := clampf(Time.get_ticks_msec() - time_start_shot,0.0,DURACTION_MAX_BONUS)
		var ease_time := duraction_press / DURACTION_MAX_BONUS
		var bonus :=ease(ease_time,EASE_REWARD_FACTION)
		var shot_power = player.Power * (1 + bonus)
		shot_direction = shot_direction.normalized()
		
		#var state_data 	:=PlayerStateData.new()
		#state_data.shot_direction = shot_direction
		#state_data.shot_power = shot_power
		
		var state_data = PlayerStateData.buid().set_shot_direction(shot_direction).set_shot_power(shot_power)
		transaction_state(Player.State.SHOOTING,state_data)
		

func can_pass() -> bool:
	return true
